package moe.eairpeter.sfpapi;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;

import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

import me.clip.placeholderapi.external.EZPlaceholderHook;

/**
 * @author EAirPeter
 */
public class PlaceholderHook extends EZPlaceholderHook {

    static AtomicReference<Map<UUID, PlayerInfo>> refMap =
        new AtomicReference<>(new HashMap<>());

    public PlaceholderHook(Plugin plugin) {
        super(plugin, "slimefun");
    }

    @Override
    public String onPlaceholderRequest(Player player, String id) {
        if (player == null)
            return "";
        PlayerInfo pi = refMap.get().get(player.getUniqueId());
        if (pi == null)
            return "";
        switch (id) {
        case "level":
            return pi.levels;
        case "rank":
            return pi.rank;
        case "progress":
            return pi.progress;
        default:
            return "";
        }
    }

}
